package com.csb.service.impl;

import com.csb.config.MyConstants;
import com.csb.mapper.ClassifyMapper;
import com.csb.pojo.AddUserRole;
import com.csb.pojo.Classify;
import com.csb.pojo.ClassifyTypesRate;
import com.csb.service.ClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;
import java.util.Map;

@Service
public class ClassifyServiceImpl implements ClassifyService {
    @Autowired
    private ClassifyMapper classifyMapper;

    @Override
    public List<Classify> findAllClassifyInfo(Map<String, Object> cond) {
        return classifyMapper.findAllClassifyInfo(cond);
    }

    @Override
    public boolean saveClassify(Classify classify) {
        return classifyMapper.saveClassify(classify)>0;
    }

    @Override
    public boolean modifyClassify(Classify classify) {
        return classifyMapper.modifyClassify(classify)>0;
    }

    @Override
    public boolean deleteClassify(Integer id) {
        return classifyMapper.deleteClassify(id)>0;
    }

    @Override
    public boolean batchDelClassify(String[] ids) {
        try {
            return classifyMapper.batchDelClassify(ids)>0;
        } catch (Exception e) {
            e.printStackTrace();
            // 手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return false;
        }

    }

    @Override
    @Cacheable(value = "rateClassify", key = "'getClassifyTypesRate'")
    public List<ClassifyTypesRate> getClassifyTypesRate() {
        return classifyMapper.getClassifyTypesRate();
    }
}
